﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EzDesk.Modularity;
using EzDesk.DesktopClient;
using EzDesk.DesktopClient.Event;
using System.Windows;
using Microsoft.Practices.Unity;

namespace EzDesk.DesktopClient.OptionsModule
{
    public class OptionsModuleInfo : IModule
    {
        public OptionsViewModel OptionsViewModel { get; set; }


        public IModule Initialize()
        {
            IMClientUnityContainer.Instance.RegisterType<IOptionsView, OptionsView>();
            OptionPopupEvent.Instance.Subscribe(this.OnOptionPopup);
            LogoutEvent.Instance.Subscribe(this.OnLogout);
            return this;
        }

        private void OnLogout(LogoutArgs obj)
        {
            CloseOptionWindow();
        }

        private void CloseOptionWindow()
        {
            if (OptionsViewModel != null)
                OptionsViewModel.View.CloseWindowView();
        }

        protected void OnOptionPopup(OptionPopupArgs args)
        {
            if (UserManagement.Instance.LogUserState.IsAvailable)
            {
                CloseOptionWindow();

                OptionsViewModel = new OptionsViewModel();
                OptionsViewModel.View.ShowWindowView();

            }
        }
    }
}
